import pymysql
from hashlib import sha1
conn = pymysql.connect(host='120.78.6.253',port=3306,user='root',password='123456',db='bbs',charset='utf8')
name = input('用户名:')
pwd = input('密码:')
cursor = conn.cursor()
pwd = sha1(pwd.encode('utf8')).hexdigest()
sql = 'select password from user1 where username=%s'
cursor.execute(sql,name)
psw = cursor.fetchall()
print(psw)
if psw ==():
    print('用户名错误')
elif pwd == psw[0][0]:
    print('登录成功')
else:
    print('密码错误')
conn.commit()
cursor.close()
conn.close()